using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ObviousCode.Stately;
using StatelyCompiler;

namespace ObviousCode.Stately.Compiler.Parser
{
	public class CompilerContext
	{
		public CompilerContext() {
            TransformData = new TransformData();
        }
		
		public Exception Exception { get; set; }		

        public Stack<Token> TokenStack { get; private set; }


        public Token NextState1 { get; set; }
        public Token NextState2 { get; set; }

        public Transition.Kind NextTransitionType { get; set; }
        public TransformData TransformData { get; private set; }

        public List<Token> TokenList
        {
            set
            {
                TokenStack = new Stack<Token>();

                for (int i = value.Count - 1; i >= 0; i--) TokenStack.Push(value[i]);

                States.AddRange(
                    value
                    .Where(t => t.Kind == Token.TokenType.State)
                    .Select(t => t.Data)
                    .Distinct());
            }
        }
        
        public string StartingState { get { return TransformData.StartingState; } set { TransformData.StartingState = value; } }
        public List<string> States { get { return TransformData.States; } }
        public List<Transition> Transitions { get { return TransformData.Transitions; } }

        public string FailMessage { get; set; }
    }
}